package com.spudtech
{
    
    import flash.geom.*;
    import flash.events.*;
    import flash.display.*;
    
    import com.spudtech.utils.*;
    
    
    public class SpudGame extends SpudObject
    {
        
        protected static var _mainApp : SpudGame;
        
        protected var _scene : SpudScene;
        
        public function SpudGame(width : uint,
                                 height : uint,
                                 init_scene : SpudScene = null)
        {
            super();
            
            _mainApp = this;
            
            scrollRect = new Rectangle(0,0,width,height);
            
            scene = init_scene;
            
            SpudRoot.init();
            
            addEventListener(Event.ENTER_FRAME,this.onFrameEnter);
            
        }
        
        public static function get mainApp() : SpudGame
        {
            return _mainApp;
        }
        
        public function get scene() : SpudScene
        {
            return _scene;
        }
        public function set scene(new_scene : SpudScene) : void
        {
            if (_scene != null)
            {
                // We already have a scene
                // Destroy it
                
                _scene.destroy();
                
            }
            
            _scene = new_scene;
            
            if (_scene != null)
            {
                // We have a new scene
                // Initialize it
                
                _scene.begin();
                
            }
            
        }
        
        
        public function onFrameEnter(event : Event) : void
        {
            update();
        }
        
        
        override public function update() : void
        {
            super.update();
            
            this.graphics.clear();
            
            SpudRoot.screen.render(null,null,this.graphics);
            
        }
        
    }
    
}
